$(function(){
	//alert($)
	var index = 0;
	var oLi = $('.header-bot ul li');
	var oSpan = $('.header-bot ul li span');
	var oMusic = $('.header-bot .music');
	var oSubMenu = $('.header-bot .sub-menu');
	var oPlayA = $('.header-bot .sub-menu a');
	var oSound = $('.header-bot .sound');
	var oList = $('#main .time .line .list');
	var oItem = $('#main .mod .top .item');
	oLi.hover(function(){//音乐导航
		var _index=$(this).index();
		//console.log(_index);
		oSpan.eq(_index).css('background','#'+Color()).stop(true,true).animate({'height':'50px'},300)
		oMusic.toArray()[0].src='/mp3/'+_index+'.mp3';
		oMusic.toArray()[0].play();
		
	},function(){
		var _index=$(this).index();
		oSpan.eq(_index).stop(true,true).animate({'height':'0px'},300);
	});
	//二级菜单音乐
	oPlayA.hover(function(){
		oSound.toArray()[0].play();
	});

	//随机颜色封装
	function Color(){
		var _color = parseInt(Math.random()*16777215).toString(16)
		while ( _color.length<6 )
		{
		_color='0'+_color;
		}
		return _color;
	};
	oLi.click(function(){
		$(this).addClass("header-active").siblings().removeClass("header-active");
	});

	//时光画轴
	oList.click(function(){
		//alert( $(this).index() )
		$(this).addClass("cur").siblings().removeClass("cur");
	});
	oItem.click(function(){
		$(this).addClass("on").siblings().removeClass("on");
	});

	//吸顶盒
	$(window).scroll(function(){
		var H = $(window).scrollTop();
		if ( H>200 ){
			$("#header .header-bot").addClass("addfixed");
			$("#main .time").addClass("time-fixed");
		}else{
			$("#header .header-bot").removeClass("addfixed");
			$("#main .time").removeClass("time-fixed");
		}
	});
/************************************************/
	//主页幻灯片left
	var $wrapulLi = $(".content-top .center ul li");
	var len = $wrapulLi.length;
	var oMspan =$('#main .content-top .left span');
	var oMC = $('#main .content-top');
	var oRight = $('#main .content-top .center .nav-arrows #right');
	var oLeft = $('#main .content-top .center .nav-arrows #left');
	var timer = null;
	oMspan.click(function(){
		index = $(this).index();
		Tab();
	});
	//center
	oRight.click(function(){
		index ++;
		index%=len;
		Tab();
	});
	oLeft.click(function(){
		index --;
		index = index <0?len-1:index;
		Tab();
	});
	
	//鼠标移入停止移出继续
	oMC.hover(function(){
		clearInterval(timer);
	},function(){
		timeAuto();
	});

	//自动轮播
	timeAuto();
	function timeAuto(){
		timer = setInterval(function(){
			index++;
			index%=len;
			Tab();
		},2000);
	};

	//封装
	function Tab(){
		$wrapulLi.eq(index).fadeIn(2000).siblings('li').fadeOut(2000);
		$wrapulLi.eq(index).css('display','block').siblings('li').css('display','none')
		
		//$wrapulLi.eq(index).animate({height:340},"3000").siblings('li').animate({height:0},"3000")
		oMspan.eq(index).addClass('auto').siblings('span').removeClass('auto');
	};	



/********************************************************/


		//喜欢
	var arrt = $('.content-center .left ul li .date font');
	var loveNum = $('.content-center .left ul li .date font span');
	arrt.click(function(){
		index = $(this).index();
		loveNum.html(Number( loveNum.html() ) + 1);
		$(this).addClass("addclick");
		//loveNum = iNum;
		//console.log(  );
	});

	//广告滚动条
	bannerMsg( $(".con .scroll-wrap ul") , $(".con .scroll-wrap ul li") , $(".con .scroll-wrap") );
	function bannerMsg( $wrapUl ,$wrapli , $box ){
		var index2 = 0 ;
		var timeToday = null;
		timeAuto();
		function timeAuto(){
			timeToday = setInterval(function(){
				index2++;
				play();
			},2000);
		};
		
		$box.hover(function(){
			clearInterval(timeToday);
		},function(){
			timeAuto();
		});
		//封装
		function play(){
			$wrapUl.animate({"marginTop":-40*(index2+1)},500,function(){
				if(index2 == $wrapli.length - 2){
					$wrapUl.css("marginTop",-40+"px");
					index2 = 0
				}
			});
		}
	};


	//登录框
	var oALogin = $('.banner-msg #login a.login');
	var oAZhuce = $('.banner-msg #login a.zhuce');
	var oTap = $('.banner-msg .tab');
		oALogin.mouseover(function(){
			oTap.css('display','block').stop(true,true).animate({'height':'200px'},300);
		});
		oTap.mouseleave(function(){
			oTap.css('display','none').stop(true,true).animate({'height':'0px'},300);
		});


	//分页

	$(".page").delegate(".pageCon .pageItem", "click", function() {//选择第几页
		var $this = $(this),
			$parents = $this.parents(".page"),
			pageSel = $this.index() + 1;
			
		selPage($parents, pageSel);
	}).delegate(".pageItem.prevPage", "click", function() {//选择上一页
		var $parents = $(this).parents(".page"),
			pageSel = $parents.find(".pageItem.selected").index() + 1;
			
		selPage($parents, pageSel - 1);
	}).delegate(".pageItem.nextPage", "click", function() {//选择下一页
		var $parents = $(this).parents(".page"),
			pageSel = $parents.find(".pageItem.selected").index() + 1;
			
		selPage($parents, pageSel + 1);
	});
	
	
	
	//选择第几页
	function selPage($page, val) {
		var $items = $page.find(".pageCon .pageItem"),
			val = parseInt(val, 10),
			maxPage = $items.length;
		
		if(val <= 0) {//不能小于1页
			val = 1;
		}else if(val > maxPage) {//不能大于最大页面
			val = maxPage;
		}
		
		//是否不用上一页
		if(val === 1) {
			$page.addClass("prevTop");
		}else {
			$page.removeClass("prevTop");
		}
		
		//是否不用下一页
		if(val === maxPage) {
			$page.addClass("nextTop");
		}else {
			$page.removeClass("nextTop");
		}
		
		$items.removeClass("selected");
		$items.eq(val - 1).addClass("selected");
	}

	/* 今日焦点幻灯片 */
		/*banner轮播图*/
	bannerAuto( $(".banner .tab a") , $(".banner .btn a") , $(".banner .slide-wrap ul") , $(".banner") , "click" ,$(".banner .slide-wrap") , 3000 );
	function bannerAuto( $tabA , $btnA , $wrapUl , $box , event , $w , T ){
		var index1 = 0;
		var nowDate = new Date();
		var timer = null;
		var W = $w.width();
		
		$tabA[event](function(){
			index1 = $(this).index();
			$(this).addClass("active").siblings().removeClass("active");
			//console.log(index1)
			$wrapUl.animate({"marginLeft":-W*(index1+1)},500);
		});

		$btnA.click(function(){
			if(	new Date() - nowDate > 600 ){
				nowDate = new Date();
				var n = $(this).index();
				//n=0 代表左按钮 n=1 右按钮
				/*if( n ){
					index1++;
				}else{
					index1--;
				}
				*/
				n?index1++:index1--;

				play();
			}
		});

		//鼠标放入banner停止轮动
		$box.hover(function(){//鼠标移入
			clearInterval(timer);
		},function(){//鼠标移开
			timeAuto();
		});

		//自动轮播
		timeAuto();
		function timeAuto(){
			timer = setInterval(function(){
				index1++;
				play();
			},T);
		};

		//函数封装
		function play(){
			var aindex = index1;
			//console.log($tabA.length)
			if( aindex == $tabA.length){
				aindex = 0;
			}else if(aindex < 0){
				aindex = $tabA.length-1;
			}
			$tabA.eq(aindex).addClass("active").siblings().removeClass("active");
			
			$wrapUl.animate({"marginLeft":-W*(index1+1)},500,function(){
				if(index1 == $tabA.length){
					$wrapUl.css("marginLeft",-W+"px");
					index1 = 0
				}else if(index1 < 0){
					$wrapUl.css("marginLeft",-W*( $tabA.length )+"px");
					index1 = $tabA.length-1;
				};
			});
		};
	};



	/* 百度统计 */
	var _hmt = _hmt || [];
	(function() {
		var hm = document.createElement("script");
		hm.src = "https://hm.baidu.com/hm.js?1ff7a976821dd332e29fc46ff0dea975";
		var s = document.getElementsByTagName("script")[0]; 
		s.parentNode.insertBefore(hm, s);
	})();
});